package apis.youtube
{
	import flash.events.EventDispatcher;
	import flash.net.URLRequest;
	import bi.conf.Configuration;
	import flash.net.URLVariables;
	import flash.net.URLLoader;
	import flash.events.Event;
	import flash.events.ErrorEvent;
	import flash.events.HTTPStatusEvent;
	
	public class YouTubeUser extends YouTubeConnector
	{
		
		function YouTubeUser() : void {
			
		}
		
		
		public function grabInfos( user : String ) : void {
			var req : URLRequest = new URLRequest( Configuration.getInstance().getString("youtubeWsUrl") );
			var variables : URLVariables = new URLVariables();
			variables.method = "youtube.users.get_profile";
			variables.dev_id = Configuration.getInstance().getString( "youtubeDevId" );
			variables.user = user;
			
			req.data = variables;
			
			trace( variables.dev_id );
			
			var dataLoader : URLLoader = new URLLoader();
			dataLoader.addEventListener( Event.COMPLETE, onComplete ) ;
			dataLoader.addEventListener( ErrorEvent.ERROR, onError ) ;
			dataLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, onHttpStatus );
			dataLoader.load( req );
		}
		
		//_______________________________________________________________________
		//																PRIVATES
		
		
		override protected function onComplete( e : Event ) : void {
			 var l : URLLoader = e.target as URLLoader;
			 _datas = XML( l.data );
			 
			 parseDatas( );
		}
		override protected function onError( e : ErrorEvent ) : void {
			 trace( e.text );
		}
		override protected function onHttpStatus( e : HTTPStatusEvent ) : void {
			 trace("********************STATUS DE YOUTUBE*************************");
			 trace( e.status );
		}
		
		override protected function parseDatas() : void {
			 
			 trace( _datas );

			dispatchEvent( new Event( Event.COMPLETE ) );
		}
		
	}
}